<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{:session('cp.cpsysname')}--商户管理平台</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="{:config('webconfig.description');}">
    <meta name="keywords" content="{:config('webconfig.keywords');}">
    <meta name="author" content="raoob">
    <!-------------开关按钮css-------------->
    <link rel="stylesheet" href="__STATIC_URL__/static/css/bootstrapSwitch.css">
    <link rel="stylesheet" href="__STATIC_URL__/static/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="__STATIC_URL__/static/css/index.css"/>
    <link rel="stylesheet" type="text/css" href="__STATIC_URL__/static/member/css/core1.css?v=12"/>

    <link rel="stylesheet" href="__STATIC_URL__/static/css/addmchat.css"/>
    <script src="__STATIC_URL__/static/js/jquery-2.1.4.min.js"></script>
    <script src="__STATIC_URL__/static/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="__STATIC_URL__/static/js/bootstrapSwitch.js"></script>
    <script src="__STATIC_URL__/static/js/commen.js" type="text/javascript" charset="utf-8"></script>
    <script src="__STATIC_URL__/static/layer/layer.js"></script>
    <link rel="stylesheet" type="text/css" href="__STATIC_URL__/static/bootstrap-table/bootstrap-table.css"/>
    <style>
        #tablelist tr td{
            max-width:150px;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
        }
        .left-side .active a {

            color: #444a46;
            background: none;
        }
    </style>
    <script>

        $(document).ready(function () {
            if (location.hash) {
                $('a[href=' + location.hash + ']').tab('show');
            }
            $(document.body).on("click", "a[data-toggle]", function (event) {
                location.hash = this.getAttribute("href");
            });
        });
        $(window).on('popstate', function () {
            var anchor = location.hash || $("a[data-toggle=tab]").first().attr("href");
            $('a[href=' + anchor + ']').tab('show');
        });
    </script>
</head>
<body>
{include file='public/header'/}
<!------------------导航-------------------------->
<section>
    {include file='public/left'/}
    <!--------------------------主要内容区域------------------------------------->
    <div class="content">
        <div class="page-heading mgl15 mgr15">
            <ul class="breadcrumb">
                <li>
                    当前位置是&nbsp;:&nbsp;
                </li>
                <li><a href="#">门店管理</a></li>
                <li class="active" style="color: #02b87f;"> 分账设置</li>
            </ul>
        </div>
        <div class="panel panel-default mgl15 mgr15">
            <div class="panel-heading addCharts" style="backgroad:#ededed;">分账设置
            </div>
            <div class="panel-body">

                <ul id="myTab" class="nav nav-tabs">
                    <li class="active"><a href="#jichu" data-toggle="tab">基础信息</a></li>
                    <li><a href="#userlist" data-toggle="tab">分账人员管理</a></li>
                    <li><a href="#profitlist" data-toggle="tab">分账记录</a></li>
                </ul>

                <div id="myTabContent" class="tab-content" style="padding-top:15px;">

                    <div class="tab-pane fade in active" id="jichu">
                        <form class="form-horizontal adminex-form" action="" method="post" id="fenzhangset" name="form"
                              enctype="multipart/form-data">
                            <div class="form-group">
                                <input type="hidden" value="{$machinfo['id']}" id="id" name="id">
                                <input type="hidden" value="setup" id="type" name="type">
                                <label class="col-sm-2 col-sm-2 control-label">是否开启分账：</label>
                                <div class="col-sm-10" id="mdtz">
                                    <div class="switch switch-small" data-animated="true" id="is_profit"
                                         data-on-label="开启" data-off-label="关闭">
                                        <input type="checkbox" name="is_profit" value="Y" class="is_profit" checked/>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">分账时间：</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control ipt4" id="profit_time"
                                           value="{$machinfo['profit_time']}" name="profit_time" readonly="readonly"
                                           id="search_date" class="form-control"
                                           placeholder="请选择" style="width: 297px">
                                </div>
                            </div>
                            <div style="text-align: center">
                                <button type="button" onclick="addform()" class="btn btn-primary">保存设置</button>
                            </div>
                        </form>

                    </div>

                    <div class="tab-pane fade" id="userlist">
                        <table class="table table-hover">
                            <caption>分账人员列表</caption>
                            <span class="btn btn-success pull-right" id="addaccount"
                                  style="margin-top: -5px;">添加分账人员</span>

                            <thead>
                            <tr>
                                <th>分账人员类型</th>
                                <th>姓名</th>
                                <th>账号</th>
                                <th>比例/金额</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {volist name="userlist" id="vo"}
                            <tr>
                                <td>{:getprofit_type($vo['type'])}</td>
                                <td>{$vo['name']}</td>
                                <td>{$vo['account']}</td>
                                <td>{$vo['fz_num']}</td>
                                <td>{$vo['status']}</td>
                                <td><a href="javascript:void(0)" onclick="del({$vo['id']})">删除</a></td>
                            </tr>
                            {/volist}

                            </tbody>
                        </table>

                        <div class="form-group">

                        </div>
                    </div>
                    <div class="tab-pane fade in" id="profitlist">
                        <div class="panel mgl15 mgr15">
                            <div class="panel-heading addCharts" style="background:#ededed;">分账明细
                                <a href="javascript:;" onclick="load();" class="btn btn-info"
                                   style="float: right;  margin-top: -7px;">点击下载</a>

                            </div>
                            <div class="panel-body">
                                <table class="table table-bordered table-striped" id="tablelist">

                                </table>
                            </div>
                        </div>
                    </div>
                </div>


            </div>
        </div>
        {include file='public/footer'/}
    </div>
</section>

<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">添加分账人</h4>
            </div>
            <div class="modal-body">
                <form role="form" class="form-horizontal adminex-form" id="account_form">
                    <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label">账号类型：</label>
                        <div class="col-sm-10">
                            <input type="hidden" class="form-control ipt4" id="mid" value="{$machinfo['id']}"
                                   name="mid">
                            <input type="hidden" class="form-control ipt4" value="addaccount" name="type">
                            <div class="col-sm-10">
                                <select class="form-control ipt4" id="profit_type" name="profit_type">
                                    <option value="MERCHANT_ID">商户号</option>
                                    <option value="PERSONAL_WECHATID">个人微信号</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label">账号：</label>
                        <div class="col-sm-10">
                            <input type="text" minlength="19" maxlength="19" class="form-control ipt4 profit_ipt"
                                   id="account" name="account">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label">名称：</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control ipt4 profit_ipt" id="name" name="name">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label">分账类型：</label>
                        <div class="col-sm-10">
                            <select class="form-control ipt4" id="fz_type" name="fz_type">
                                <option value="B">按比例分</option>
                                <option value="G">固定金额</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label">比例/金额：</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control ipt4 profit_ipt" id="fz_num" name="fz_num">
                        </div>
                        <div>比例以小数点计最大值为1即100%,小数点默认保留2位,填入固定金额的单位为元</div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="sendform()">提交更改</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel2">分账明细</h4>
            </div>
            <div class="modal-body">
                <table class="table table-bordered">
                    <tbody id="templateHtml"></tbody>
                </table>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
</body>
<!--<script src="__STATIC_URL__/static/js/template.js"></script>-->
<script src="__STATIC_URL__/static/bootstrap-table/bootstrap-table.js"></script>
<script src="__STATIC_URL__/static/bootstrap-table/bootstrap-table-zh-CN.js"></script>
<script src="__STATIC_URL__/static/laydate/laydate.js"></script>
<script src="/wntable.js?v=2"></script>

<script>
    laydate.render({
        elem: '#profit_time',
        type: 'time'
    });
    $(function () {
        var is_profit = "{$machinfo['is_profit']}";
        if (is_profit == "N") {
            $('#is_profit').bootstrapSwitch('setState', false);
        } else {
            $('#is_profit').bootstrapSwitch('setState', true);
        }
        $('#addaccount').click(function () {
            $('.goods_ipt').val("");
            $('#is_default').bootstrapSwitch('setState', false);
            $('#myModal').modal('show');
        })

    });

    function load() {
        layer.msg('暂未开放');
        // $("#type").val("out_excel");
        //
        // $.ajax({
        //     url: "{:url('pay/paylog')}",
        //     data: $('#machform').serialize(),
        //     dataType: "json",
        //     async: false,
        //     type: "post",
        //     success: function (res) {
        //         window.location.href = res ;
        //     }
        // })
    }

    $(function () {
        var type = "profitlist";
        var url = "{:url('')}";
        getcolumn(type, url)

    });


    //搜索
    function searchforms() {
        $("#tablelist").bootstrapTable('refresh');
    }

    function sendform() {
        $.ajax({
            type: "POST",
            url: "{:url('')}",
            cache: false,
            dataType: "json",
            async: false,
            data: $('#account_form').serialize(),

            success: function (data) {
                if (data.result_code == "SUCCESS") {
                    layer.msg('操作成功');
                    setTimeout("window.location.reload()", 1000)
                } else {
                    layer.msg('操作失败'+data.result_msg);
                }
            }

        })
    }

    function del(id) {
        $.ajax({
            type: "POST",
            url: "{:url('')}",
            cache: false,
            dataType: "json",
            async: false,
            data: {
                'fz_id': id,
                'type': "delaccount"
            },

            success: function (data) {
                if (data.result_code == "SUCCESS") {
                    layer.msg('已加入后台执行');
                    setTimeout("window.location.reload()", 2000)

                } else {
                    layer.msg('操作失败');
                }
            }

        })
    }
    function mtfenzhang(id) {
        var datas = {};

        $.ajax({
            type: "POST",
            url: "{:url('')}",
            cache: false,
            dataType: "json",
            async: false,
            data: {
                'id': id,
                'type': "mtfenzhang"
            },

            success: function (data) {
                if (data.result_code == "SUCCESS") {
                    layer.msg(data.result_msg);
                    setTimeout("window.location.reload()", 1000)
                } else {
                    layer.msg('操作失败 : ' + data.result_msg);
                }
            }

        });
    }


    function addform() {
        $.ajax({
            type: "POST",
            url: "{:url('')}",
            cache: false,
            dataType: "json",
            async: false,
            data: $('#fenzhangset').serialize(),
            success: function (data) {
                console.log(data);
                if (data.result_code == "SUCCESS") {
                    layer.msg('操作成功');
                    setTimeout("window.location.reload()", 1000)
                } else {
                    layer.msg('操作失败');
                }
            }

        })


    }


</script>

</html>
